package com.lll.simple.rpc.config;

import com.lll.simple.rpc.common.RegistryType;
import com.lll.simple.rpc.common.RpcProperties;
import com.lll.simple.rpc.provider.RpcProvider;
import com.lll.simple.rpc.registry.RegistryFactory;
import com.lll.simple.rpc.registry.RegistryService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 16:51 2021/1/31
 * @Modified By:
 */
@Configuration
@EnableConfigurationProperties(RpcProperties.class)
public class RpcProviderAutoConfiguration {
    @Resource
    private RpcProperties rpcProperties;

    @Bean
    public RpcProvider rpcProvider() throws Exception {
        RegistryType registryType = RegistryType.valueOf(rpcProperties.getRegistryType());
        RegistryService registryService = RegistryFactory.getInstance(rpcProperties.getRegistryAddr(), registryType);
        return new RpcProvider(rpcProperties.getServerPort(), registryService);
    }
}
